<?php
namespace app\exam\controller;

use app\exam\model\CandidateModel;
class Candidate extends Common
{
    /*
        考生登录
        method: POST
        params:
            user_name  用户登录的名称
            exam_id 参加考试的id信息
    */
    public function login()
    {
        if($this->_method != 'post'){
            //只接受post请求
            $res = array(
                'code' => '0001'
            );
            $this->_response($res);
        }

        if(empty($this->args['user_name']) || is_numeric($this->args['exam_id']) == false){
            $res = array(
                'code' => '0002'
            );
            $this->_response($res);
        }

        $CandidateModel = new CandidateModel();
        $ret = $CandidateModel->Login($this->args['user_name'], $this->args['exam_id']);

        if($ret === false){
            $res = array(
                'code' => '0003'
            );
        }elseif(empty($ret['code']) == false){
            $res = $ret;
        }else{
            $res = array(
                'code' => '0',
                'data' => $ret
            );
        }

        $this->_response($res);
    }
}
